package love.yuanmengrobot.attendancesystem.dao;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/24 23:33
 */

import love.yuanmengrobot.attendancesystem.dao.SQL.SqlString;
import love.yuanmengrobot.attendancesystem.entity.AttendanceDate;
import love.yuanmengrobot.attendancesystem.entity.StudentAttendanceDate;
import love.yuanmengrobot.attendancesystem.util.JdbcUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class StudentAttendanceDao {


    public ArrayList<StudentAttendanceDate> queryByMemberId(String memberid) {

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            ArrayList<StudentAttendanceDate> list = new ArrayList<StudentAttendanceDate>();
            conn = JdbcUtil.getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(SqlString.selectAttendanceByMemberId(memberid));

            //判断该学生签到状态
            while (rs.next()) {
                StudentAttendanceDate studentAttendanceDate = new StudentAttendanceDate(
                        rs.getString("b.atname"),
                        rs.getString("a.atstime"),
                        rs.getString("a.atsstate"));
                list.add(studentAttendanceDate);
            }
            if (list.size() > 0) return list;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {//回收资源
            JdbcUtil.close(rs, stmt, conn);
        }
        return null;
    }

    ;



}
